<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<!--edge浏览器H5兼容设置-->
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<!--360浏览器H5兼容设置-->
		<meta name="renderer" content="webkit" />
		<title>益农商城</title>
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<!--导入核心文件-->
		<script src="../bootstrap3/js/holder.js"></script>
		<link href="../bootstrap3/css/bootstrap.css" rel="stylesheet" type="text/css">
		<script src="../bootstrap3/jquery-1.9.1.min.js"></script>
		<script src="../bootstrap3/js/bootstrap.js"></script>
		<!-- 字体图标 -->
		<link rel="stylesheet" href="../bootstrap3/font-awesome-4.7.0/css/font-awesome.css" />
		<link rel="stylesheet" type="text/css" href="../css/top.css" />
		<link rel="stylesheet" type="text/css" href="../css/index.css" />
		<link rel="stylesheet" type="text/css" href="../css/layout.css" />
		<link rel="stylesheet" type="text/css" href="../css/reg.css" />
		<link rel="stylesheet" type="text/css" href="../css/footer.css" />
	</head>
	<body>
		<!--头部-->
		<header class="header">
			<img class="logo" src="../images/index/yinong-shop.png" alt=""/>
			<span class="pull-right"><small>欢迎访问</small><b>益农商城</b></span>
		</header>
		<!--主体-->
		<div class="container mycontent text-left">
			<!--透明层 -->
			<div class="regDiv">
				<p>新用户注册</p>
				<!--表单开始-->
				<form id="form-reg" class="form-horizontal" role="form">
					<!--用户名-->
					<div class="form-group">
						<label class="col-md-3 control-label">名字：</label>
						<div class="col-md-8">
							<input name="username" type="text" class="form-control" placeholder="请输入用户名">
						</div>
					</div>
					<!--用户类型-->
					<div class="form-group">
						<label class="col-md-3 control-label">用户类型：</label>
						<div class="col-md-8">
							<input type="radio" name="userType" value="0" checked="checked">买家
							<input type="radio" name="userType" value="1">卖家
						</div>
					</div>
					<!--密码-->
					<div class="form-group">
						<label class="col-md-3 control-label"> 密码：</label>
						<div class="col-md-8">
							<input name="password" type="password" class="form-control" placeholder="请输入密码">
						</div>
					</div>
					<!--确认密码-->
					<div class="form-group">
						<label class="col-md-3 control-label"> 确认密码：</label>
						<div class="col-md-8">
							<input name="pwConfirm" type="password" class="form-control" placeholder="请再次输入密码">
						</div>
					</div>
					<!--提交按钮-->
					<div class="form-group">
						<label class="col-md-3 control-label"></label>
						<div class="col-md-8">
							<input id="btn-reg" class="btn btn-primary" type="button" value="立即注册" />
							<span class="pull-right"><small>已经有账号？</small><a href="login.html">登录</a></span>
						</div>
					</div>
				</form>
			</div>
		</div>
		<!--页脚开始-->
		<div class="clearfix"></div>
		<footer class="footer">
			<!-- 品质保障，私人定制等-->
			<div class="text-center rights container">
				<div class="col-md-offset-2 col-md-2">
					<span class="fa fa-thumbs-o-up"></span>
					<p>品质保障</p>
				</div>
				<div class="col-md-2">
					<span class="fa fa-search-minus"></span>
					<p>产地直销</p>
				</div>
				<div class="col-md-2">
					<span class="fa fa-shopping-bag"></span>
					<p>品牌特供</p>
				</div>
				<div class="col-md-2">
					<span class="fa fa-car"></span>
					<p>极速货运</p>
				</div>
			</div>

			<!--联系我们、下载客户端等-->
			<div class="container beforeBottom text-center">
				<div class="col-md-offset-1 col-md-3">

				</div>
				<div class="col-md-4 callus text-center">
					<div class="col-md-4">
						<ul>
							<li><a href="#"><p>买家帮助</p></a></li>
							<li><a href="#">新手指南</a></li>
							<li><a href="#">服务保障</a></li>
							<li><a href="#">常见问题</a></li>
						</ul>
					</div>
					<div class="col-md-4">
						<ul>
							<li><a href="#"><p>商家帮助</p></a></li>
							<li><a href="#">商家入驻</a></li>
							<li><a href="#">商家后台</a></li>
						</ul>
					</div>
					<div class="col-md-4">
						<ul>
							<li><a href="#"><p>关于我们</p></a></li>
							<li><a href="#">关于益农</a></li>
							<li><a href="#">联系我们</a></li>
							<li>
								<span class="fa fa-wechat"></span>
								<span class="fa fa-weibo"></span>
							</li>
						</ul>
					</div>
				</div>
			</div>
			<!-- 页面底部-备案号 #footer -->
			<div class="col-md-12 text-center bottom">
				Copyright © 2022 dnsc.cn All Rights Reserved 京ICP备08963888号-45 <a target="_blank" href="http://www.dnsc.cn/">益农科技集团有限公司</a>
				版权所有
			</div>
		</footer>
		<!--页脚结束-->
		<script type="text/javascript">
			/*监听按钮一*/
			$("#btn-reg").click(function () {
				let $loginForm = $(this);
				let $parent = $loginForm.parent().parent().parent();
				let username = $parent.find("input[name='username']").val();
				let password = $parent.find("input[name='password']").val();
				let pwConfirm = $parent.find("input[name='pwConfirm']").val();
				if (username.trim().length === 0 || password.trim().length === 0) {
					alert("用户名和密码不能为空!");
					return;
				}
				if (username.trim().length > 10) {
					alert("用户名长度不能超过10!");
					return;
				}
				if (password.trim().length < 6) {
					alert("密码长度不能小于6!");
					return;
				}
				if (!/^[\u0391-\uFFE5\w]+$/.test(username)) {
					alert("只允许汉字、英文字母、数字及下划线!");
					return;
				}
				if (password !== pwConfirm) {
					alert("密码两次输入应该一致！");
					return;
				}
				$.ajax({
					url:"http://localhost:8080/user/register",
					type:"POST",
					data:$("#form-reg").serialize(),
					dataType:"JSON",
					success:function (json) {
						if (json.stateCode == 200 ) {
							alert("注册成功"+json.stateCode);
							location.href = "login.html";
						} else {
							alert("注册失败")
						}
					},
					error:function (xhr) {
						alert("注册产生了 "+xhr.status+" 错误")
					}
				})
			})
		</script>
	</body>



</html>